package cn.youframe.frame.tag;

import cn.youframe.frame.beans.CommTypeValVO;
import cn.youframe.frame.util.ToolsUtil;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * User: Administrator
 * DateTime: 12-4-25: 下午3:28
 */
public class CacheValTag  extends TagSupport {
    private String typeId;//类型ID
    private String valId;//值ID
    private String getVal;//表示区那个字段的值，默认取值：extVal、status、remark

    public int doEndTag() throws JspException {
        try {
            String tagVal=null;
            CommTypeValVO valVo= ToolsUtil.getValueVO(typeId, valId);
            if(valVo==null){
                tagVal="";
            }else{
                if(getVal==null || getVal.equals("")){
                    tagVal=valVo.getValName();
                }else{
                    if(tagVal.equalsIgnoreCase("extVal")){
                        tagVal=valVo.getExtVal();
                    }else if(tagVal.equalsIgnoreCase("remark")){
                        tagVal=valVo.getMemo();
                    }else if(tagVal.equalsIgnoreCase("status")){
                        tagVal=valVo.getEnable();
                    }else{
                        tagVal="";
                    }
                }
            }
            pageContext.getOut().write(tagVal);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.doEndTag();
    }

    public void setTypeId(String typeId) {
        this.typeId = typeId;
    }

    public void setValId(String valId) {
        this.valId = valId;
    }

    public void setGetVal(String getVal) {
        this.getVal = getVal;
    }

    public String getTypeId() {
        return typeId;
    }

    public String getValId() {
        return valId;
    }

    public String getGetVal() {
        return getVal;
    }
}
